package com.tgy.JUC.BlockingQueueDemo;

import java.util.concurrent.ArrayBlockingQueue;

/***
 * @ClassName: Test3
 * @Description: 阻塞一直等待
 * @Auther: 送你一块二向箔
 * @Date: 9:53 2022/3/14
 * @version : V1.0
 */
public class Test3 {
    public static void main(String[] args) {
        run1();
    }

    public static void run1() {
        ArrayBlockingQueue<String> strings = new ArrayBlockingQueue<>(3);
        try {
            strings.put("a");
            strings.put("b");
            strings.put("c");
            //位置不够一直阻塞等待
            strings.put("d");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void run2() {
        ArrayBlockingQueue<String> strings = new ArrayBlockingQueue<>(3);
        try {
            strings.take();
            strings.take();
            strings.take();
            //位置不够一直阻塞等待
            strings.take();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
